package android.cmpe451.group7.activity;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapClickListener;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;

public class SetCoordinateActivity extends Activity {

	double latitude = 0;
	double longitude = 0;
	private GoogleMap map;
	String placeName;
	String countryName;
	String cityName;
	String tags;
	String tagId;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_set_coordinate);
		//LatLng cityLocation = new LatLng(41.085449, 29.046904);
		Intent intent = getIntent();
		tags = intent.getStringExtra("tag");
		placeName = intent.getStringExtra("placeName");
		countryName = intent.getStringExtra("country");
		cityName = intent.getStringExtra("city");
		tagId = intent.getStringExtra("tagId");
		
		map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
				.getMap();
		map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(41.085449, 29.046904), 15));
		map.animateCamera(CameraUpdateFactory.zoomTo(17), 2000, null);
		map.setMyLocationEnabled(true);
		map.setOnMapClickListener(new OnMapClickListener() {

			@Override
			public void onMapClick(LatLng point) {
				// TODO Auto-generated method stub
				map.clear();
				latitude = point.latitude;
				longitude = point.longitude;
				Marker location = map.addMarker(new MarkerOptions()
						.position(point));
				location.setIcon(BitmapDescriptorFactory
						.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW));
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.map, menu);
		return true;
	}
	

	public void returnCoordinate(View view) {
		Intent intent = new Intent(getApplicationContext(),
				CreatePlaceActivity.class);
		
		intent.putExtra("longitude", String.valueOf(longitude));
		intent.putExtra("latitude", String.valueOf(latitude));		
		intent.putExtra("tags", tags);
		intent.putExtra("country", countryName);
		intent.putExtra("city", cityName);
		intent.putExtra("placeName", placeName);
		intent.putExtra("tagId", tagId);
		startActivity(intent);
	}

}
